﻿/********************************************************************************************************************
* Author:	Christos Polydorou																						*
* Email:	std04237@di.uoa.gr																						*
* Purpose:	This script is used in order to create the stored procedure "usp_entity_updateattributevalue" that		*
*			updates the value for an ettribute of an entity.														*
********************************************************************************************************************/

CREATE PROCEDURE [dbo].[usp_entity_updateattributevalue]
	@entityid nvarchar(50),
	@attributename nvarchar(50),
	@value nvarchar(50)
AS
	DECLARE @attributeid bigint
	DECLARE @categoryid bigint

	SELECT @categoryid = Entities.Category
	FROM Entities
	WHERE Entities.ID = @entityid

	SELECT @attributeid = id										/* get the id of the attribute */
	FROM Attributes
	WHERE Attributes.name = @attributename and Attributes.category = @categoryid

	UPDATE [Entity-Attribute]
	SET Value = @value
	WHERE [Entity-Attribute].Entity = @entityid and [Entity-Attribute].attribute = @attributeid

RETURN 0